﻿using System.Collections.Generic;
using Titul.Help.Models;
using System.Linq;
using Neo4j.DataProvider;

namespace Titul.Help.Storages
{
    public class ProductStorage : SimpleStorage<Product>
    {
        private Neo4jDataProvider<Product> _provider;
        public ProductStorage()
        {
            _provider = new Neo4j.DataProvider.Neo4jDataProvider<Product>(this.Client);
        }

        public override IEnumerable<Product> All
        {
            get
            {
                return _provider.All;
            }
        }

        public override Product Create(Product product)
        {
            var model = _provider.CreateIfNotExist(product, "Id");
            return model;
        }

        public override Product Single(int id)
        {
            var model = _provider.Single(id);
            return model;
        }

        public override Product Single(string seoUrl)
        {
            var model=_provider.GetByPropertyValue("SeoUrl", seoUrl);
            return model;
        }

        public override Product Edit(Product product)
        {
            if (product.Id != 0)
                _provider.Update(product);
            return product;
        }
    }
}
